package org.redis.cluster.transport.netty.server;

import org.redis.cluster.transport.exception.TransportException;
import org.redis.cluster.transport.server.ServerChannel;

import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;

public class NettyServerChannel implements ServerChannel {
	
	private ChannelFuture channelFuture;
	private EventLoopGroup bossGroup;
	private EventLoopGroup workerGroup;
	
	public NettyServerChannel(ChannelFuture channelFuture,EventLoopGroup bossGroup,EventLoopGroup workerGroup) {
		this.channelFuture=channelFuture;
		this.bossGroup=bossGroup;
		this.workerGroup=workerGroup;
	}

	@Override
	public boolean shutdown() {
		try {
			channelFuture.channel().close();
			bossGroup.shutdownGracefully();
			workerGroup.shutdownGracefully();
			return true;
		}
		catch(Exception e) {
			throw new TransportException(e);
		}
	}

}